package cn.edu.uestc.software.service;

import cn.edu.uestc.software.mapper.RoleMapper;
import cn.edu.uestc.software.pojo.Role;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class RoleService {
    @Resource
    private RoleMapper roleMapper;

    public Map<String,Object> selectRoles(int page,
                                          String roleName,
                                          String roleLevel){
        Map<String,Object> map = new HashMap<>();
        int index=(page-1)*10;
        List<Role> roles = roleMapper.selectRoles(index,roleName,roleLevel);
        int counts = roleMapper.selectRoleCounts(roleName, roleLevel);
        map.put("code",0);
        map.put("msg","");
        map.put("count",counts);
        map.put("data",roles);
        return map;
    }

    public Map<String,Object> selectAllRoles(){
        Map<String,Object> map = new HashMap<>();
        List<Role> roles = roleMapper.selectAllRoles();
        map.put("code",0);
        map.put("msg","");
        map.put("data",roles);
        return map;
    }

    public Map<String,Object> insert(Role role) {
        Map<String, Object> map = new HashMap<>();
        roleMapper.insert(role);
        map.put("code", 200);
        map.put("msg", "新增权限成功");
        map.put("data",role);
        return map;
    }

    public Map<String,Object> update(Role role) {
        Map<String, Object> map = new HashMap<>();
        roleMapper.update(role);
        map.put("code", 200);
        map.put("msg", "更新权限成功");
        map.put("data",role);
        return map;
    }

    public Map<String,Object> delete(Integer id) {
        Map<String, Object> map = new HashMap<>();
        roleMapper.delete(id);
        map.put("code", 200);
        map.put("msg", "删除权限成功");
        map.put("data",id);
        return map;
    }
}













